<?php
// 连接数据库等操作
require_once 'databaseConnection.php';

if (isset($_POST['predetermineId'], $_POST['bookings'])) {
    $predetermineId = $_POST['predetermineId'];
    $bookings = $_POST['bookings'];
    // 执行数据更新操作
    $pdo = connectToDatabase();
    // 准备更新语句
    $query = 'UPDATE predetermine SET 
                customerName = :customerName,
                customerPhone = :customerPhone,
                roomType = :roomType,
                roomCount = :roomCount,
                checkinDate = :checkinDate,
                checkoutDate = :checkoutDate,
                adultCount = :adultCount,
                childCount = :childCount,
                scheduledTime = :scheduledTime,
                roomNumber = :roomNumber,
                paymentMethod = :paymentMethod,
                bookingMethod = :bookingMethod,
                remarks = :remarks
              WHERE predetermine_id = :predetermineId';
    $statement = $pdo->prepare($query);
    // 绑定参数
    $statement->bindParam(':predetermineId', $predetermineId, PDO::PARAM_INT);
    $statement->bindParam(':customerName', $bookings['customerName']);
    $statement->bindParam(':customerPhone', $bookings['customerPhone']);
    $statement->bindParam(':roomType', $bookings['roomType']);
    $statement->bindParam(':roomCount', $bookings['roomCount'], PDO::PARAM_INT);
    $statement->bindParam(':checkinDate', $bookings['checkinDate']);
    $statement->bindParam(':checkoutDate', $bookings['checkoutDate']);
    $statement->bindParam(':adultCount', $bookings['adultCount'], PDO::PARAM_INT);
    $statement->bindParam(':childCount', $bookings['childCount'], PDO::PARAM_INT);
    $statement->bindParam(':scheduledTime', $bookings['scheduledTime']);
    $statement->bindParam(':roomNumber', $bookings['roomNumber']);
    $statement->bindParam(':paymentMethod', $bookings['paymentMethod']);
    $statement->bindParam(':bookingMethod', $bookings['bookingMethod']);
    $statement->bindParam(':remarks', $bookings['remarks']);
    // 执行更新
    $result = $statement->execute();

    if ($result) {
        echo json_encode(['status' => 'success']);
    } else {
        echo json_encode(['status' => 'error', 'message' => '无法更新数据']);
    }
} else {
    echo json_encode(['status' => 'error', 'message' => '无效请求']);
}
